package com.jsb.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.jsb.common.config.Const;
import com.jsb.common.utils.JsonUtil;
import com.jsb.common.utils.SmsUtil;
import com.jsb.common.utils.StringUtils;

@Service
public class SmsSendService {
	
	public static final String SMSAUTHTOKEN = "dad0307ec8794e648b236063b78101c0";
	public static final String SMSACCOUNT = "8aaf070858bd37890158ccd0b5ad04e9";
//	public static final String SMSAPPID = "8a216da8592b16a1015938d4129f03f0";
	
	public static final String SCENE_ANSWER_ADOPT_TEMPLALTE = "145451";
	public static final String SCENE_ANSWER_ENOUGH_TEMPLALTE = "145452";
	public static final String SCENE_REDBAG_REWARD_TEMPLALTE = "145455";
	public static final String SCENE_QUESTION_TOEND_TEMPLALTE = "145453";
	
	public static final String SCENE_COUNSELOR_NOPASS_TEMPLALTE = "148776";
	public static final String SCENE_ANSWER_ADOPTCOMFORT_TEMPLALTE = "148773";
	public static final String SCENE_COUNSELOR_PASS_TEMPLALTE = "148770";
	public static final String SCENE_USER_FINDPWD_TEMPLALTE = "148766";
	public static final String SCENE_USER_REGISTER_TEMPLALTE = "148764";
	
	
	/**
	 * 
	 * @param phone  要发送的手机号码，多个用","隔开
	 * @param scene  发送短信场景
	 * @param str    需要传递的参数，须按照顺序传递
	 * @return
	 */
	public String sendNotify(String SMSAPPID,String phone,String scene,String  str[]){
		Map<String,String> map = new HashMap<String,String>();
		if(StringUtils.isEmpty(phone)){
			map.put("status", "FAIL");
			map.put("msg", "手机号phone不能为空");
			return JsonUtil.toJson(map);
		}
		if(StringUtils.isEmpty(scene)){
			map.put("status", "FAIL");
			map.put("msg", "发送短信场景scene不能为空");
			return JsonUtil.toJson(map);
		}
//		if(null==str||str.length==0){
//			map.put("status", "FAIL");
//			map.put("msg", "参数str不能为空");
//			return JsonUtil.toJson(map);
//		}
		if(phone.contains(",")){
			String[] phonearray = phone.split(",");
			for (String string : phonearray) {
				if(!StringUtils.isMobile(string)){
					map.put("status", "FAIL");
					map.put("msg", "手机号格式不正确");
					return JsonUtil.toJson(map);
				}
			}
		}else{
			if(!StringUtils.isMobile(phone)){
				map.put("status", "FAIL");
				map.put("msg", "手机号格式不正确");
				return JsonUtil.toJson(map);
			}
		}
		String sendSms = null;
		switch (scene) {
		case Const.SCENE_ANSWER_ADOPT:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_ANSWER_ADOPT_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_ANSWER_ENOUGH:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_ANSWER_ENOUGH_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_REDBAG_REWARD:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_REDBAG_REWARD_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_QUESTION_TOEND:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_QUESTION_TOEND_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_ANSWER_ADOPTCOMFORT:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_ANSWER_ADOPTCOMFORT_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_COUNSELOR_PASS:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_COUNSELOR_PASS_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_COUNSELOR_NOPASS:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_COUNSELOR_NOPASS_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_USER_REGISTER:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_USER_REGISTER_TEMPLALTE, phone, str);
			break;
		case Const.SCENE_USER_FINDPWD:
			sendSms = SmsUtil.sendSms(SMSAPPID,SCENE_USER_FINDPWD_TEMPLALTE, phone, str);
			break;
		default:
			break;
		}
		return sendSms;
	}
	/**
	 * 发送短信
	 * @param phone
	 * @param str
	 * @return
	 */
	public String sendSms(String appid,String template,String phone,String str[]){
		return SmsUtil.sendSms(appid,template, phone, str);
	}
}
